package meal;
/*
 * Nathaniel Cherry:cherryn | Updated: 10.23.11 - Created class with getter, setter, and toString functions
 * Nathaniel Cherry:cherryn | Updated: 10.23.11 - Added JavaDoc comments for all functions;
 * 		added Null Constructor; and modified regular constructor to use setter methods.
 */


/**
 * A container that represents a meal and the ingredients and directions associated with it.
 *
 * <p>Meal class is used to associate a meal(thought of as a unique string representing its name),
 * with it's ingredients and how to make it. It also holds some additional information such as
 * rating to help the Scheduler better prepare meal plans.
 */
public class Meal {
	private String name;
	private long lastUsed;
	private double rating;

	private Ingredient ingredients[];
	private Direction directions[];

	/**
	 * Creates a meal in which ingredients, directions, and name are <code>null</code> and
	 * rating is zero.
	 */
	// Last updated: 10.23.11
	public Meal() {
	}

	/**
	 * Creates a meal with specified name, ingredients, directions and rating, where
	 * rating is in the range (0.0 - 1.0).
	 * @param name name of meal
	 * @param ingr ingredients
	 * @param dir directions
	 * @param rating rating, must be between zero and one inclusive.
	 */
	// Last updated: 10.23.11
	public Meal(String name, Ingredient ingr[], Direction dir[], double rating) {
		setRating(rating);
		setName(name);
		setIngredients(ingr);
		setDirections(dir);
		setLastHad(0);
	}

	/**
	 * Creates a meal with specified name, ingredients, directions and rating, where
	 * rating is in the range (0.0 - 1.0).
	 * @param name name of meal
	 * @param ingr ingredients
	 * @param dir directions
	 * @param rating rating, must be between zero and one inclusive.
	 */
	// Last updated: 10.23.11
	public Meal(String name, Ingredient ingr[], Direction dir[], double rating, long lastUsed) {
		setRating(rating);
		setName(name);
		setIngredients(ingr);
		setDirections(dir);
		setLastHad(lastUsed);
	}
	/**
	 * Sets when the Meal was last had.
	 * @param lastUsed value representing the time since Epoch when last
	 * used.
	 */
	public void setLastHad(long lastUsed) {
		this.lastUsed = lastUsed;
	}
	/**
	 * @return long value representing time in millseconds since Epoch
	 * when last used.
	 */
	public long getLastHad() {
		return this.lastUsed;
	}
	/**
	 *	Sets the Meal's ingredients to be ingredients, overriding the old igredients.
	 *  @param ingredients the ingredients necessary for the Meal.
	 */
	// Last updated: 10.23.11
	public void setIngredients(Ingredient[] ingredients) {
		this.ingredients = ingredients;
	}

	/**
	 *	Sets the Meal's directions to be directions overriding the old direction.
	 *	@param directions the directions for the Meal
	 */
	// Last updated: 10.23.11
	public void setDirections(Direction[] directions) {
		this.directions = directions;
	}

	/**
	 * Renames meal as name.
	 * @param name name
	 */
	// Last updated: 10.23.11
	public void setName(String name) {
		this.name=name;
	}

	/**
	 * Sets the base rating to rating in the range 1.0-0.0.
	 * @param rating the rating, must be greater than or equal to zero and less than or equal to one.
	 */
	// Last updated: 10.23.11
	public void setRating(double rating) {
		//TODO: Validated rating to make sure it conforms to a legal state for rating.
		this.rating = rating;
	}

	/**
	 * Returns directions associated with Meal if exist.
	 * @return Returns an array containing the directions for the meal or Null if none exist.
	 */
	// Last updated: 10.23.11
	public Direction[] getDirections() {
		return this.directions;
	}

	/**
	 * Returns ingredients associated with Meal if exist.
	 * @return Returns an array containing the ingredients for the meal or Null of none exist.
	 */
	// Last updated: 10.23.11
	public Ingredient[] getIngredients() {
		return this.ingredients;
	}

	/**
	 * Return the name of the meal.
	 * @return Returns the name of the meal or Null if meal is not named.
	 */
	// Last updated: 10.23.11
	public String getName() {
		return this.name;
	}

	/**
	 * Returns Returns the rating of the meal in the range 0.0-1.0.
	 * @return Returns the rating of the meal in the range 0.0-1.0.
	 */
	// Last updated: 10.23.11
	public double getRating() {
		return this.rating;
	}

	/**
	 * Returns a string representation of Meal. If name, directions, or ingredients are
	 * not set will represent them as with 'Null'.
	 * For example, a Meal:
	 *
	 * <blockquote><pre>
	 * meal=new Meal();
	 * meal.setIngredients(new Ingredients[]{ new Ingredient("eggs",2) };<pre></blockquote>
	 *
	 * Will be represented as:
	 *
	 * <blockquote><pre>
	 * [null: 0.00000 Ingredients: null Directions:[2 null Rice]]
	 *
	 * </pre></blockquote>
	 * @return String representation of Meal, including name, rating, ingredients, and directions.
	 */
	// Last updated: 10.23.11
	public String toString() {
		return String.format("[%s: %g Ingredients:%s Directions:%s]",
				name,
				rating,
				java.util.Arrays.toString(ingredients),
				java.util.Arrays.toString(directions));
	}
}
